<template>

  <div  style="height: 100%;">
  <div class="app">
    <div class="tit"><span>溯源列表</span><button>标签管理</button></div>
    <div class="con">
      <div class="add">
        <span @click="addHandler">➕</span>
        <p>添加溯源</p>
      </div>
      <div class="suYuanList" v-for="(item, index) in SuYuanStore.formDataList" :key="index">
        <header>
          <p>
            <el-icon size="16"><View /></el-icon>
            {{ item.count }}
          </p>
          <span>{{ item.time + '创建' }}</span>
          <img :src="item.nongchanghuanjingUrl" />
        </header>
        <main>
          <div class="left">
            <p>{{ item.title }}</p>
            <p>{{ '关联标签数量：' + item.muchanliang }}</p>
          </div>
          <div class="right">
            <img :src="item.canhoupinzhijianceUrl" />
          </div>
        </main>
        <div class="line"></div>
        <footer>
          <div>
            <p>
              <el-icon :size="20">
                <Link />
              </el-icon>
            </p>
            <p>关联标签</p>
          </div>
          <div>
            <p>
              <el-icon :size="20">
                <Edit />
              </el-icon>
            </p>
            <p @click="editHandler(index)">编辑</p>
          </div>
          <div>
            <p>
              <el-icon :size="20">
                <Delete />
              </el-icon>
            </p>
            <p @click="deleteHandler(index)">删除</p>
          </div>
        </footer>
      </div>
    </div>
  </div>
  </div>
</template>

<script lang="ts" setup>
import { useSuYuanStore } from '@/stores/SuYuanStore'
const props = defineProps(['curId'])
const emits = defineEmits(['changeCurId', 'formDataListIndex'])
const addHandler = () => {
  emits('changeCurId', 1)
}
const SuYuanStore = useSuYuanStore()
const deleteHandler = (index: number) => {
  SuYuanStore.formDataList.splice(index, 1)
  console.log(SuYuanStore.formDataList.length)
}
const editHandler = (index: number) => {
  ++SuYuanStore.formDataList[index].count
  emits('changeCurId', 1)
  emits('formDataListIndex', index)
}
</script>

<style lang="scss" scoped>
* {
  padding: 0;
  margin: 0;
  list-style: none;
  text-decoration: none;
  box-sizing: border-box;
}
.app {
  padding: 5px 10px;
  width: 100%;
  height: 100%;
}
.tit {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 12px;
  height: 50px;
  line-height: 50px;
  background-color: #eee;
  border: 1px solid #ccc;
  border-radius: 5px;
  span {
    margin-left: 10px;
  }
  button {
    float: right;
    height: 30px;
    line-height: 20px;
    font-size: 14px;
    line-height: 20px;
    padding: 5px 10px;
    margin: 10px 15px 0 0;
    background-color: bisque;
    border-radius: 5px;
    border: 0;
  }
}
.con {
  display: flex;
  width: 100%;
  overflow: auto;
  .add {
    flex: none;
    width: 300px;
    height: 480px;
    background-color: #f5f5f5;
    border: 1px solid #eee;
    border-radius: 5px;
    margin-right: 15px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    span {
      display: inline-block;
      height: 70px;
      width: 70px;
      line-height: 70px;
      font-size: 40px;
      background-color: #ccc;
      border-radius: 100%;
      text-align: center;
      margin-bottom: 10px;
      cursor: pointer;
    }
    p {
      font-size: 20px;
      text-align: center;
    }
  }
  .suYuanList {
    flex: none;
    width: 300px;
    height: 480px;
    background-color: #f5f5f5;
    border: 1px solid #eee;
    border-radius: 5px;
    margin-right: 15px;
    header {
      position: relative;
      width: 300px;
      color: rgb(163, 34, 34);
      p {
        position: absolute;
        left: 10px;
        top: 5px;
        height: 16px;
        line-height: 16px;
        font-size: 14px;
        font-weight: 600;
      }
      span {
        position: absolute;
        right: 10px;
        top: 5px;
        font-size: 14px;
      }
      img {
        width: 100%;
        height: 300px;
        display: block;
      }
    }
    main {
      display: flex;
      height: 80px;
      justify-content: space-between;
      padding: 10px 20px;
      .left {
        padding-top: 7px;
        flex: none;
        width: 180px;
      }
      .right {
        flex: none;
        width: 60px;
        img {
          width: 60px;
          height: 60px;
        }
      }
    }
    .line {
      width: 260px;
      height: 2px;
      background-color: #948d8d;
      margin: 10px 20px;
    }
    footer {
      display: flex;
      justify-content: space-between;
      width: 100%;
      height: 80px;
      padding: 10px 20px;
      div {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        width: 80px;
        p {
          width: 80px;
          flex: none;
          text-align: center;
        }
      }
      .el-icon {
        margin-right: 5px;
      }
    }
  }
}
</style>
